#include <list>
#include <mutex>
#include <thread>
#include <algorithm>
#include <iostream>

class lock_based_list
{
public:
	void add_to_list(int new_value);
	bool list_contains(int value_to_find);
	std::size_t size() const;
private:
	mutable std::list<int> _list;
	mutable std::mutex _mutex;
};

void lock_based_list::add_to_list(int new_value)
{
	std::lock_guard<std::mutex> guard(_mutex);
	_list.push_back(new_value);
}

std::size_t lock_based_list::size() const
{
	std::lock_guard<std::mutex> guard(_mutex);
	return _list.size();
}

bool lock_based_list::list_contains(int value_to_find)
{
	std::lock_guard<std::mutex> guard(_mutex);
	return std::find(_list.begin(),_list.end(),value_to_find) != _list.end();
}

void thread_func1(lock_based_list& list);

int main()
{
	lock_based_list list0;
	std::thread thread1(thread_func1,std::ref(list0));
	for (int i = 0; i < 10; i++) {
		list0.add_to_list(i);
	}
	thread1.join();
	std::cout << "size: " << list0.size() << std::endl;
	std::cout << std::boolalpha << list0.list_contains(5) << std::endl;
}

void thread_func1(lock_based_list& list)
{
	for (int i = 0; i < 10; i++) {
		list.add_to_list(i+10);
	}
}